package com.renu.jdependencyanalyser.freemarker;

import com.intellij.ide.fileTemplates.impl.UrlUtil;
import com.renu.jdependencyanalyser.core.JarBorderGene;
import com.renu.jdependencyanalyser.freemarker.data.DependencyJarData;
import freemarker.template.Template;

import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;

@Deprecated
public class JarDependencyProcessor extends AbstractProcessor{
    private DependencyJarData dependencyJarData;



    public JarDependencyProcessor(JarBorderGene jarBorderGene) {
        super();
        this.dependencyJarData = new DependencyJarData(jarBorderGene.getBorderJars(),jarBorderGene.getDependencyNode());
    }

    @Override
    protected Object getModel() {
        HashMap<String, Object> model = new HashMap<>();
        model.put("borderJarIds",dependencyJarData.getBorderJarIds());
        model.put("dpdcyRlts",dependencyJarData.getDependencyRelationList());
        model.put("dpdcyJarLabels",dependencyJarData.getDependencyJarLabels());
        return model;
    }

    @Override
    protected Template getTemplate() throws IOException {
        String templateContent = UrlUtil.loadText(JarDependencyProcessor.class.getResource(File.separator + "template" + File.separator + "DpdcyJarTemplate.ftl"));
        stringTemplateLoader.putTemplate("DpdcyJarTemplate",templateContent);
        return configuration.getTemplate("DpdcyJarTemplate");
    }

    @Override
    protected Writer getWriter() {
        return new StringWriter();
    }

}
